package com.huadi.firematerialident.controller;

import com.huadi.firematerialident.po.*;
import com.huadi.firematerialident.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.websocket.server.PathParam;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller("/admin")
public class AdminController {
    @Autowired
    NormalUserServiceImpl normalUserService;
    @Autowired
    IdentifierServiceImpl identifierService;
    @Autowired
    ReviewerServiceImpl reviewerService;
    @Autowired
    UserService userService;
    @Autowired
    ApplicationServiceImpl applicationService;
    @Autowired
    AppraisalServiceImpl appraisalService;
    @Autowired
    FireInfoServiceImpl fireInfoService;
    @Autowired
    FireMaterialEvidenceInfoServiceImpl fireMaterialEvidenceInfoService;
    @Autowired
    ReviewServiceImpl reviewService;



    public int permissionVerification(){
        if(userService.getRole().equals("admin")){
            return 1;
        }
        else{
            return 0;
        }
    }

    //对普通用户信息的增删改查
    @GetMapping("/adminNormalUserAdd")
    public String addNormalUserOps(
            @RequestParam("NUserCount") String NUserCount,
            @RequestParam("NPassword") String NPassword,
            @RequestParam("NName") String NName,
            @RequestParam("NSex") String NSex,
            @RequestParam("NBirth") LocalDate NBirth,
            @RequestParam("NPhone") String NPhone, Model model){



        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        NormalUser normalUser = new NormalUser();
        normalUser.setNUserCount(NUserCount);
        normalUser.setNUserID();
        normalUser.setNPassword(NPassword);
        normalUser.setNName(NName);
        normalUser.setNSex(NSex);
        normalUser.setNBirth(NBirth);
        normalUser.setNPhone(NPhone);

        if(normalUserService.addNormalUser(normalUser)==0){
            model.addAttribute("msg","添加失败");

        }
        else{
            model.addAttribute("msg","添加成功");
        }
        return "/admin/normalList";
    }


    @GetMapping("/adminNormalUserDel")
    public String delNormalUserOps(@PathParam("normalUserid") String nUserID,Model model){


        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        if(normalUserService.deleteNormalUserByID(nUserID)==0){
            model.addAttribute("msg","删除失败");
        }
        else{
            model.addAttribute("msg","删除成功");
        }
        return "/admin/normalList";
    }

    @GetMapping("/adminNormalUserSel")
    @ResponseBody
    public String selNormalUserOps(@PathParam("normalUserid") String nUserID,Model model){


        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = normalUserService.selectNormalUserByID(nUserID);
        if(list.isEmpty()){
            model.addAttribute("msg","没有查询到数据。");
            return null;
        }
        else{
            model.addAttribute("msg","查询成功！");
            return userService.ListToJSON(list.size(),list);
        }

    }


    @GetMapping("/adminNormalUserUpdate")
    public String updateNormalUser(@RequestParam("NUserID") String NuserID,
                                   @RequestParam("NUserCount") String NUserCount,
                                   @RequestParam("NPassword") String NPassword,
                                   @RequestParam("NName") String NName,
                                   @RequestParam("NSex") String NSex,
                                   @RequestParam("NBirth")LocalDate NBirth,
                                   @RequestParam("NPhone") String NPhone, Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        NormalUser normalUser = new NormalUser();
        normalUser.setNUserID(NuserID);
        normalUser.setNUserCount(NUserCount);
        normalUser.setNPassword(NPassword);
        normalUser.setNName(NName);
        normalUser.setNSex(NSex);
        normalUser.setNBirth(NBirth);
        normalUser.setNPhone(NPhone);


        if(normalUserService.updateNormalUser(normalUser)==0){
            model.addAttribute("msg","修改失败！");
        }
        else{
            model.addAttribute("msg","修改成功！");
        }
        return "/admin/normalList";
    }

    @GetMapping("/adminGetAllNormalUser")
    @ResponseBody
    public String getAllNormalUser(Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = normalUserService.getAllNormalUser();
        if(list.isEmpty()){
            model.addAttribute("msg","没有找到数据");
            return "/admin/normalList";
        }
        else{
            return userService.ListToJSON(list.size(),list);
        }
    }


    //对审查员信息的增删改查
    @GetMapping("/adminReviewerAdd")
    public String addReviewerOps(
            @RequestParam("RevCount") String count,
            @RequestParam("RevPassword") String password,
            @RequestParam("RevName") String name,
            @RequestParam("RevSex") String sex,
            @RequestParam("RevBirth") LocalDate birth,
            @RequestParam("RevPhone") String phone,Model model){



        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Reviewer reviewer = new Reviewer();
        reviewer.setRevID();
        reviewer.setRevCount(count);
        reviewer.setRevPassword(password);
        reviewer.setRevName(name);
        reviewer.setRevSex(sex);
        reviewer.setRevBirth(birth);
        reviewer.setRevPhone(phone);

        if(reviewerService.addReviewer(reviewer)==0){
            model.addAttribute("msg","添加失败");

        }
        else{
            model.addAttribute("msg","添加成功");
        }
        return "/admin/ReviewerList";
    }


    @GetMapping("/adminReviewerAel")
    public String delReviewerOps(@PathParam("reviewerid") String revID, Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }


        if(reviewerService.deleteReviewerByID(revID)==0){
            model.addAttribute("msg","删除失败");
        }
        else{
            model.addAttribute("msg","删除成功");
        }
        return "/admin/ReviewerList";
    }

    @GetMapping("/adminReviewerSel")
    @ResponseBody
    public String selReviewerOps(@PathParam("reviewerid") String revID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = reviewerService.selectReviewerByID(revID);
        if(list.isEmpty()){
            model.addAttribute("msg","没有查询到数据。");

        }
        else{
            model.addAttribute("msg","查询成功！");
        }
        return userService.ListToJSON(list.size(),list);
    }

    @GetMapping("/adminReviewerUpdate")
    public String updateReviewer(@RequestParam("RevID") String id,
                                 @RequestParam("RevCount") String count,
                                 @RequestParam("RevPassword") String password,
                                 @RequestParam("RevName") String name,
                                 @RequestParam("RevSex") String sex,
                                 @RequestParam("RevBirth") LocalDate birth,
                                 @RequestParam("RevPhone") String phone,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Reviewer reviewer = new Reviewer();
        reviewer.setRevID(id);
        reviewer.setRevCount(count);
        reviewer.setRevPassword(password);
        reviewer.setRevName(name);
        reviewer.setRevSex(sex);
        reviewer.setRevBirth(birth);
        reviewer.setRevPhone(phone);

        if(reviewerService.updateReviewer(reviewer)==0){
            model.addAttribute("msg","修改失败！");
        }
        else{
            model.addAttribute("msg","修改成功！");
        }
        return "/admin/ReviewerList";
    }

    @GetMapping("/adminGetAllreviewer")
    public String getAllReviewer(Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = reviewerService.getAllReviewer();
        if(list.isEmpty()){
            model.addAttribute("msg","没有找到数据");
            return "/admin/ReviewerList";
        }
        else{
            return userService.ListToJSON(list.size(),list);
        }

    }



    //对鉴定员信息的增删改查
    @GetMapping("/adminIdentAdd")
    public String addIdentifierOps(
            @RequestParam("IdentCount") String count,
            @RequestParam("IdentPassword") String password,
            @RequestParam("IdentName") String name,
            @RequestParam("IdentSex") String sex,
            @RequestParam("IdentBirth") LocalDate birth,
            @RequestParam("IdentPhone") String phone,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Identifier identifier = new Identifier();
        identifier.setIdentID();
        identifier.setIdentCount(count);
        identifier.setIdentPassword(password);
        identifier.setIdentName(name);
        identifier.setIdentSex(sex);
        identifier.setIdentBirth(birth);
        identifier.setIdentPhone(phone);

        if(identifierService.addIdentifier(identifier)==0){
            model.addAttribute("msg","添加失败");

        }
        else{
            model.addAttribute("msg","添加成功");
        }
        return "/admin/IdentList";
    }


    @GetMapping("/adminIdentDel")
    public String delIdentifierOps(@PathParam("identifierid") String identID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        if(identifierService.deleteIdentifierByID(identID)==0){
            model.addAttribute("msg","删除失败");
        }
        else{
            model.addAttribute("msg","删除成功");
        }
        return "/admin/IdentList";
    }

    @GetMapping("/adminIdentSel")
    @ResponseBody
    public String selIdentifierOps(@PathParam("identifierid") String identID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = identifierService.selectIdentifierByID(identID);
        if(list.isEmpty()){
            model.addAttribute("msg","没有查询到数据。");
        }
        else{
            model.addAttribute("msg","查询成功！");
        }
        return userService.ListToJSON(list.size(),list);
    }



    @GetMapping("/adminIdentUpdate")
    public String updateIdentifier(@RequestParam("IdentID") String id,
                                   @RequestParam("IdentCount") String count,
                                   @RequestParam("IdentPassword") String password,
                                   @RequestParam("IdentName") String name,
                                   @RequestParam("IdentSex") String sex,
                                   @RequestParam("IdentBirth") LocalDate birth,
                                   @RequestParam("IdentPhone") String phone,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Identifier identifier = new Identifier();
        identifier.setIdentID(id);
        identifier.setIdentCount(count);
        identifier.setIdentPassword(password);
        identifier.setIdentName(name);
        identifier.setIdentSex(sex);
        identifier.setIdentBirth(birth);
        identifier.setIdentPhone(phone);

        if(identifierService.updateIdentifier(identifier)==0){
            model.addAttribute("msg","修改失败！");
        }
        else{
            model.addAttribute("msg","修改成功！");
        }
        return "/admin/IdentList";
    }

    @GetMapping("/adminGetAllIdent")
    @ResponseBody
    public String getAllIdentifier(Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = identifierService.getAllIdentifier();
        if(list.isEmpty()){
            model.addAttribute("msg","没有找到数据");
            return "/admin/IdentList";
        }
        else{
            return userService.ListToJSON(list.size(),list);
        }
    }



    //对申请表的增删改查
    @GetMapping("/adminAppAdd")
    public String addApplication(
            @RequestParam("MEID") String meid,
            @RequestParam("NUserID") String userid,
            @RequestParam("InspectionUnitName") String iname,
            @RequestParam("InspectionUnitAdd") String iadd, Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Application application = new Application();
        application.setAppID();
        application.setMEID(meid);
        application.setNUserID(userid);
        application.setInspectionUnitName(iname);
        application.setInspectionUnitAdd(iadd);

        if(applicationService.addApplication(application)==0){
            model.addAttribute("msg","添加失败");

        }
        else{
            model.addAttribute("msg","添加成功");
        }
        return "/admin/appList";
    }

    @GetMapping("/adminAppDel")
    public String delApplication(@PathParam("appID") String appID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        if(applicationService.deleteApplicationByID(appID)==0){
            model.addAttribute("msg","删除失败");
        }
        else{
            model.addAttribute("msg","删除成功");
        }
        return "/admin/appList";
    }

    @GetMapping("/adminAppSel")
    @ResponseBody
    public String selApplication(@PathParam("appID") String appID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = applicationService.selectApplicationByID(appID);
        if(list.isEmpty()){
            model.addAttribute("msg","没有查询到数据。");
        }
        else{
            model.addAttribute("msg","查询成功！");
        }
        return userService.ListToJSON(list.size(),list);
    }

    @GetMapping("/adminAppUpdate")
    public String updateApplication(@RequestParam("AppID") String appid,
                                    @RequestParam("MEID") String meid,
                                    @RequestParam("NUserID") String userid,
                                    @RequestParam("InspectionUnitName") String iname,
                                    @RequestParam("InspectionUnitAdd") String iadd, Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Application application = new Application();
        application.setAppID(appid);
        application.setMEID(meid);
        application.setNUserID(userid);
        application.setInspectionUnitName(iname);
        application.setInspectionUnitAdd(iadd);

        if(applicationService.updateApplication(application)==0){
            model.addAttribute("msg","修改失败！");
        }
        else{
            model.addAttribute("msg","修改成功！");
        }
        return "/admin/appList";
    }


    @GetMapping("/adminGetAllApp")
    @ResponseBody
    public String getAllApp(Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = applicationService.getAllApplication();
        if(list.isEmpty()){
            model.addAttribute("msg","没有找到数据");
            return "/admin/appList";
        }
        else{
            return userService.ListToJSON(list.size(),list);
        }
    }


    //对鉴定表的增删改查
    @GetMapping("/adminApsAdd")
    public String addAps(
            @RequestParam("AppID") String appid,
            @RequestParam("IdentID") String identid, Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Appraisal appraisal = new Appraisal();
        appraisal.setApsID();
        appraisal.setAppID(appid);
        appraisal.setIdentID(identid);

        if(appraisalService.addAppraisal(appraisal)==0){
            model.addAttribute("msg","添加失败");
        }
        else{
            model.addAttribute("msg","添加成功");
        }
        return "/admin/apsList";
    }

    @GetMapping("/adminApsDel")
    public String delAps(@PathParam("apsID") String apsID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        if(appraisalService.deleteAppraisalByID(apsID)==0){
            model.addAttribute("msg","删除失败");
        }
        else{
            model.addAttribute("msg","删除成功");
        }
        return "/admin/appList";
    }

    @GetMapping("/adminApsSel")
    @ResponseBody
    public String selAps(@PathParam("apsID") String apsID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = appraisalService.selectAppraisalByID(apsID);
        if(list.isEmpty()){
            model.addAttribute("msg","没有查询到数据。");
        }
        else{
            model.addAttribute("msg","查询成功！");
        }
        return userService.ListToJSON(list.size(),list);
    }

    @GetMapping("/adminApsUpdate")
    public String updateAps(@RequestParam("ApsID") String apsid,
                            @RequestParam("AppID") String appid,
                            @RequestParam("IdentID") String identid,
                            @RequestParam("ApsConclusion") String conclu,
                            @RequestParam("RevStatus") String rstatus,
                            @RequestParam("ArchivingStatus") String astatus, Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Appraisal appraisal = (Appraisal) appraisalService.selectAppraisalByID(apsid);
        appraisal.setAppID(appid);
        appraisal.setIdentID(identid);
        appraisal.setApsConclusion(conclu);
        appraisal.setRevStatus(rstatus);
        appraisal.setArchivingStatus(astatus);

        if(appraisalService.updateAppraisal(appraisal)==0){
            model.addAttribute("msg","修改失败！");
        }
        else{
            List<Map<String,Object>> list = appraisalService.selectAppraisalByID(appraisal.getApsID());
            model.addAttribute("msg","修改成功！");
        }
        return "/admin/apsList";
    }

    @GetMapping("/adminGetAllAps")
    public String getAllAps(Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = appraisalService.getAllAppraisal();
        if(list.isEmpty()){
            model.addAttribute("msg","没有找到数据");
            return "/admin/apsList";
        }
        else{
            return userService.ListToJSON(list.size(),list);
        }
    }


    //对审查表的增删改查
    @GetMapping("/adminRevAdd")
    public String addReview(
            @RequestParam("ApsID") String apsid,
            @RequestParam("RevID") String revid, Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Review review = new Review();
        review.setReviewID();
        review.setApsID(apsid);
        review.setRevID(revid);

        if(reviewService.addReview(review)==0){
            model.addAttribute("msg","添加失败");

        }
        else{
            model.addAttribute("msg","添加成功");
        }
        return "/admin/revList";
    }


    @GetMapping("/adminRevDel")
    public String delReview(@PathParam("revID") String revID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        if(reviewerService.deleteReviewerByID(revID)==0){
            model.addAttribute("msg","删除失败");
        }
        else{
            model.addAttribute("msg","删除成功");
        }
        return "/admin/revList";
    }

    @GetMapping("/adminRevSel")
    @ResponseBody
    public String selReview(@PathParam("revID") String revID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = reviewerService.selectReviewerByID(revID);
        if(list.isEmpty()){
            model.addAttribute("msg","没有查询到数据。");

        }
        else{
            model.addAttribute("msg","查询成功！");
        }
        return userService.ListToJSON(list.size(),list);
    }

    @GetMapping("/adminRevUpdate")
    public String updateReview(@RequestParam("ReviewID") String rid,
            @RequestParam("ApsID") String apsid,
            @RequestParam("RevID") String revid,
            @RequestParam("RevConclution") String conclu,
            @RequestParam("ArchovingStatus") String astatus,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        Review review = new Review();
        review.setReviewID(rid);
        review.setApsID(apsid);
        review.setRevID(revid);
        review.setRevConclusion(conclu);
        review.setArchivingStatus(astatus);

        if(reviewService.updateReview(review)==0){
            model.addAttribute("msg","修改失败！");
        }
        else{
            List<Map<String,Object>> list = reviewerService.selectReviewerByID(review.getRevID());
            model.addAttribute("msg","修改成功！");
        }
        return "/admin/revList";
    }

    @GetMapping("/adminGetAllRev")
    public String getAllRev(Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = reviewerService.getAllReviewer();
        if(list.isEmpty()){
            model.addAttribute("msg","没有找到数据");
            return "/admin/RevList";
        }
        else{
            return userService.ListToJSON(list.size(),list);
        }
    }

    //对物证表的增删改查
    @GetMapping("/adminMEAdd")
    public String addME(
            @RequestParam("FireInfoID") String fid,
            @RequestParam("METype") String metype,
            @RequestParam("MoreInfo") String moreinfo, Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        FireMaterialEvidenceInfo fireMaterialEvidenceInfo = new FireMaterialEvidenceInfo();
        fireMaterialEvidenceInfo.setMEID();
        fireMaterialEvidenceInfo.setFireInfoID(fid);
        fireMaterialEvidenceInfo.setMEType(metype);
        fireMaterialEvidenceInfo.setMoreInfo(moreinfo);

        if(fireMaterialEvidenceInfoService.addFireMaterialEvidenceInfo(fireMaterialEvidenceInfo)==0){
            model.addAttribute("msg","添加失败");
        }
        else{
            model.addAttribute("msg","添加成功");
        }
        return "/admin/MEList";
    }

    @GetMapping("/adminMEDel")
    public String delME(@PathParam("MEID") String meID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        if(fireMaterialEvidenceInfoService.deleteFireMaterialEvidenceInfoByID(meID)==0){
            model.addAttribute("msg","删除失败");
        }
        else{
            model.addAttribute("msg","删除成功");
        }
        return "/admin/MEList";
    }


    @GetMapping("/adminMESel")
    @ResponseBody
    public String selME(@PathParam("MEID") String meID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = fireMaterialEvidenceInfoService.selectFireMaterialEvidenceInfoByID(meID);
        if(list.isEmpty()){
            model.addAttribute("msg","没有查询到数据。");

        }
        else{
            model.addAttribute("msg","查询成功！");
        }
        return userService.ListToJSON(list.size(),list);
    }


    @GetMapping("/adminMEUpdate")
    public String updateME(
            @RequestParam("MEID") String meid,
            @RequestParam("FireInfoID") String fid,
            @RequestParam("METype") String metype,
            @RequestParam("MoreInfo") String moreinfo,
            @RequestParam("ArchivingStatus")  String astatus,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        FireMaterialEvidenceInfo fireMaterialEvidenceInfo = new FireMaterialEvidenceInfo();
        fireMaterialEvidenceInfo.setMEID(meid);
        fireMaterialEvidenceInfo.setFireInfoID(fid);
        fireMaterialEvidenceInfo.setMEType(metype);
        fireMaterialEvidenceInfo.setMoreInfo(moreinfo);
        fireMaterialEvidenceInfo.setArchivingStatus(astatus);


        if(fireMaterialEvidenceInfoService.updateFireMaterialEvidenceInfo(fireMaterialEvidenceInfo)==0){
            model.addAttribute("msg","修改失败！");
        }
        else{
            List<Map<String,Object>> list = fireMaterialEvidenceInfoService.selectFireMaterialEvidenceInfoByID(fireMaterialEvidenceInfo.getMEID());
            model.addAttribute("msg","修改成功！");
        }
        return "/admin/MEList";
    }

    @GetMapping("/adminGetAllME")
    @ResponseBody
    public String getAllME(Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = fireMaterialEvidenceInfoService.getAllFireMaterialEvidenceInfo();
        if(list.isEmpty()){
            model.addAttribute("msg","没有找到数据");
            return "/admin/MEList";
        }
        else{
            return userService.ListToJSON(list.size(),list);
        }
    }



    //对火灾信息表的增删改查
    @GetMapping("/adminFireInfoAdd")
    public String addFireInfo(@RequestParam("FireType") String ftype,
                              @RequestParam("FireLevel") String flevel,
                              @RequestParam("FireTime") LocalDate ftime,
                              @RequestParam("FireAdd") String fadd,
                              @RequestParam("MoreInfo") String moreinfo,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        FireInfo fireInfo = new FireInfo();
        fireInfo.setFireInfoID();
        fireInfo.setFireType(ftype);
        fireInfo.setFireLevel(flevel);
        fireInfo.setFireTime(ftime);
        fireInfo.setFireAdd(fadd);
        fireInfo.setMoreInfo(moreinfo);

        if(fireInfoService.addFireInfo(fireInfo)==0){
            model.addAttribute("msg","添加失败");
        }
        else{
            model.addAttribute("msg","添加成功");
        }
        return "/admin/FireInfoList";
    }

    @GetMapping("/adminFireInfoDel")
    public String delFireInfo(@PathParam("FireInfoID") String FireInfoID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        if(fireInfoService.deleteFireInfoByID(FireInfoID)==0){
            model.addAttribute("msg","删除失败");
        }
        else{
            model.addAttribute("msg","删除成功");
        }
        return "/admin/FireInfoList";
    }


    @GetMapping("/adminFireInfoSel")
    @ResponseBody
    public String selFireInfo(@PathParam("FireInfo") String FireInfoID,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = fireInfoService.selectFireInfoByID(FireInfoID);
        if(list.isEmpty()){
            model.addAttribute("msg","没有查询到数据。");

        }
        else{
            model.addAttribute("msg","查询成功！");
        }
        return userService.ListToJSON(list.size(),list);
    }

    @GetMapping("/adminFireInfoUpdate")
    public String updateFireInfo(@RequestParam("FireInfoID") String fid,
            @RequestParam("FireType") String ftype,
                                 @RequestParam("FireLevel") String flevel,
                                 @RequestParam("FireTime") LocalDate ftime,
                                 @RequestParam("FireAdd") String fadd,
                                 @RequestParam("MoreInfo") String moreinfo,Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        FireInfo fireInfo = new FireInfo();
        fireInfo.setFireInfoID(fid);
        fireInfo.setFireType(ftype);
        fireInfo.setFireLevel(flevel);
        fireInfo.setFireTime(ftime);
        fireInfo.setFireAdd(fadd);
        fireInfo.setMoreInfo(moreinfo);

        if(fireInfoService.updateFireInfo(fireInfo)==0){
            model.addAttribute("msg","修改失败！");
        }
        else{
            List<Map<String,Object>> list = fireInfoService.selectFireInfoByID(fireInfo.getFireInfoID());
            model.addAttribute("msg","修改成功！");
        }
        return "/admin/FireInfoList";
    }

    @GetMapping("/adminGetAllFireInfo")
    public String getAllFireInfo(Model model){

        if(permissionVerification()==0){
            model.addAttribute("msg","您没有权限");
            return "appcommit";
        }

        List<Map<String,Object>> list = fireInfoService.getAllFireInfo();
        if(list.isEmpty()){
            model.addAttribute("msg","没有找到数据");
            return "/admin/FireInfoList";
        }
        else{
            return userService.ListToJSON(list.size(),list);
        }
    }

}



